package net.akkz.dbFactory.impl;

import net.akkz.dbFactory.impl.SessionImpl;
import net.akkz.exception.SQLExcuteException;


public class StudentServer
{

	public StudentServer(){}
	
	// ==========信息获取==========
	public void test(SessionImpl session) throws SQLExcuteException
	{
		String sql = "insert into classjoin values(11103948,1)";
		
		session.excute(sql);
//		
//		sql = "insert into classjoin values(11103948,4)";
//		
//		session.excute(sql);
		
//		String sql = "delete from classjoin  where stuid = 11103948";
//		
//		session.excute(sql);
	}

	public boolean cancle(SessionImpl session, Object values[]) throws NumberFormatException, SQLExcuteException
	{
		String sql = "select * from classjoin where stuid = ? and classid = ?";
		if(session.check(sql, new String[]{String.valueOf(values[0]), String.valueOf(values[1]) }))
		{
			sql = "delete from classjoin where stuid = ? and classid = ?";
			session.excute(sql, new String[]{ String.valueOf(values[0]), String.valueOf(values[1]) } );
				
			sql = "select joined from classes where id = ?";
			int num = Integer.parseInt(session.get(sql, String.valueOf(values[1])));
			
			if(num>0)
			{
				sql = "UPDATE classes SET joined = ? WHERE id = ?";
				session.excute(sql, new String[]{ String.valueOf(--num), String.valueOf(values[1]) } );
				
				return true;
			}
		}
		
		return false;
	}

}
